import React, { Component } from 'react'

import { API } from '../../utils/axios'

import NavHeader from '../../components/NavHeader'
import HouseItem from '../../components/HouseItem'

import styles from './index.module.css'

export default class Rent extends Component {
  state = {
    // 出租房屋列表
    list: []
  }

  // 获取已发布房源的列表数据
  async getHouseList() {
    const { data } = await API.get('/user/houses');

    if (data.status === 200) {
      this.setState({ list: data.body });
    }
  }

  componentDidMount() {
    this.getHouseList()
  }

  render() {
    const { history } = this.props

    return (
      <div className={styles.root}>
        <NavHeader onLeftClick={() => history.go(-1)}>房屋管理</NavHeader>

        <HouseItem housesList={this.state.list}/>
      </div>
    )
  }
}
